package com.Controller;

import com.Service.AdminService;
import com.Utils.JWTUtil;
import com.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/Admin")
public class AdminController {
    @Autowired
    AdminService adminService;

    @PostMapping("/Login")
    public R AdminLogin(@RequestBody Map<String,String> Map_All){
        String admin=Map_All.get("admin");
        String pwd=Map_All.get("pwd");
        if(adminService.AdminLogin(admin,pwd)!=null){
            //登录成功
            Map<String, String> dataMap = new HashMap<>();
            dataMap.put("admin", admin);
            Object token = JWTUtil.getToken(dataMap);
            Map<String,Object> data=new HashMap<>();
            data.put("token",token);
            data.put("username","平台客服");
            return new R(true, data, "登录成功");
        }else
        {
            return new R(false);
        }
    }
    @GetMapping("/findAllUser")
    public R findAllUser(){
            return new R(true,adminService.findAllUser());
    }

    @GetMapping("/findAllEngineer")
    public R findAllEngineer(){
        return new R(true,adminService.findAllEngineer());
    }

    @GetMapping ("/findMoney")
    public R findMoney(){
        return new R(true,adminService.getTotalMoney());
    }
}
